<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>随机颜色效果</title>
    <style>
      body {
        font-size: 30px;
        padding: 200px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    houdunren.com
  </body>
  <script>
    function Color(elem) {
      this.elem = elem;
      this.colors = [
        "#3498db",
        "#1abc9c",
        "#e67e22",
        "#f1c40f",
        "#c0392b",
        "#f39c12"
      ];
      this.run = function() {
        setInterval(
          function() {
            let i = Math.floor(Math.random() * this.colors.length);
            this.elem.style.backgroundColor = this.colors[i];
          }.bind(this),
          1000
        );
      };
    }
    let obj = new Color(document.body);
    obj.run();
  </script>
</html>
